<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="6" :md="6" :sm="24">
            <a-form-item label="券类型">
                 <a-select v-model="queryParam.couponType" placeholder="请选择券类型"  :allowClear="true">
                  <a-select-option value="">请选择</a-select-option>
                  <a-select-option value="1">折扣券</a-select-option>
                  <a-select-option value="2">代金券</a-select-option>
                   <a-select-option value="3">展示券</a-select-option>
                   <a-select-option value="4">下载券</a-select-option>
                   <a-select-option value="5">报名券</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
           <a-col :xl="6" :lg="6" :md="6" :sm="24">
            <a-form-item label="券状态">
                 <a-select v-model="queryParam.useStatus"
                  placeholder="请选择券状态"  :allowClear="true">
                  <a-select-option value="">请选择</a-select-option>
                  <a-select-option value="0">未使用</a-select-option>
                  <a-select-option value="1">已核销</a-select-option>
                  <a-select-option value="2">已过期</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="6" :sm="24">
            <a-form-item label="所属商家">
                 <a-select v-model="queryParam.merchId" :filter-option="filterOption" show-search placeholder="请选择所属商户" :allowClear="true">
                     <a-select-option value="">请选择</a-select-option>
                  <a-select-option v-for="item in merchList" :value="item.id" :key="item.id">
                    {{ item.merchName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="6" :sm="24">
              <a-form-item label="券名称">
                <a-input placeholder="请输入券名称" v-model="queryParam.couponName"></a-input>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="6" :sm="24">
              <a-form-item label="会员名称">
                <a-input placeholder="请输入会员名称" v-model="queryParam.userName"></a-input>
              </a-form-item>
          </a-col>
        <a-col :xl="6" :lg="6" :md="6" :sm="24">
              <a-form-item label="会员手机号">
                <a-input placeholder="请输入会员手机号" v-model="queryParam.userPhone"></a-input>
              </a-form-item>
          </a-col>
           <a-col :xl="4" :lg="4" :md="4" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">查看详情</a>
        </span>

      </a-table>
    </div>

    <adh-coupon-order-modal ref="modalForm" @ok="modalFormOk"></adh-coupon-order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { getAction } from '@/api/manage'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AdhCouponOrderModal from './modules/AdhCouponOrderModal'

  export default {
    name: 'AdhCouponOrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      AdhCouponOrderModal
    },
    data () {
      return {
        description: '优惠券订单页面',
        merchList:[],
        queryParam:{
          merchId:'',
          couponType:'',
          useStatus:'',
          userInfo:'',
          couponName:'',
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
           {
            title:'劵类型',
            align:"center",
            width:90,
            dataIndex: 'couponType',
             ellipsis:true,
              customRender:function (text,row) {
              if(text=="1"){
                return "折扣券";
              }else if(text=="2"){
                return "代金券";
              }else if(text=="3"){
                return "展示券";
              }else if(text=="4"){
                return "下载券";
              }else if(text=="5"){
                return "报名券";
              }
            }
          },
          {
            title:'优惠券编号',
            align:"center",
            width:100,
             ellipsis:true,
            dataIndex: 'couponNo'
          },
           {
            title:'券名称',
            align:"center",
            width:150,
             ellipsis:true,
            dataIndex: 'couponName'
          },
          {
            title:'所属商家',
            align:"center",
             ellipsis:true,
              width:150,
            dataIndex: 'merchName'
          },
          {
            title:'会员信息',
            align:"center",
            dataIndex: 'userPhone',
             width:200,
             ellipsis:true,
            customRender:function (text,row) {
              return  (row.userName?row.userName:'')+" "+(row.userPhone?row.userPhone:'')
            }
          },
          {
            title:'劵码有效期',
            align:"center",
            width:200,
             ellipsis:true,
            dataIndex: 'validBeginTime',
            customRender:function (text,row) {
              return  row.validBeginTime+"至"+row.validEndTime
            }
          },
          {
            title:'支付金额',
            align:"center",
            width:100,
            ellipsis:true,
            dataIndex: 'advancePurchasePrice'
          },
          {
            title:'券码状态',
            align:"center",
            dataIndex: 'useStatus',
            width:100,
            ellipsis:true,
            customRender:function (text,row) {
              if(text=="0"){
                return "未使用";
              }else if(text=="1"){
                return "已核销";
              }else if(text=="2"){
                return "已过期";
              }
            }
          },
          {
            title:'领取时间',
            align:"center",
            width:100,
            ellipsis:true,
            dataIndex: 'receiveDate',
          },
          {
            title:'核销时间',
            align:"center",
            dataIndex: 'checkDate',
            width:100,
            ellipsis:true,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/order/adhCouponOrder/list",
          delete: "/order/adhCouponOrder/delete",
          deleteBatch: "/order/adhCouponOrder/deleteBatch",
          exportXlsUrl: "/order/adhCouponOrder/exportXls",
          importExcelUrl: "/order/adhCouponOrder/importExcel",
          merchList:"/merch/adhMerchInfo/getAllMerchList"
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    let that = this;
    this.getSuperFieldList();
     getAction(that.url.merchList).then((res)=>{
          if(res.success){
            that.merchList = res.result;
          }
        });
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'couponNo',text:'优惠券订单号'})
        fieldList.push({type:'string',value:'merchId',text:'商家ID'})
        fieldList.push({type:'string',value:'merchName',text:'商家名称'})
        fieldList.push({type:'string',value:'userPhone',text:'会员手机号'})
        fieldList.push({type:'string',value:'userName',text:'会员昵称'})
        fieldList.push({type:'string',value:'userId',text:'会员ID'})
        fieldList.push({type:'string',value:'couponName',text:'优惠券名称'})
        fieldList.push({type:'int',value:'couponType',text:'优惠券类型'})
        fieldList.push({type:'date',value:'validBeginTime',text:'有效开始时间'})
        fieldList.push({type:'date',value:'validEndTime',text:'有效结束时间'})
        fieldList.push({type:'number',value:'advancePurchasePrice',text:'提前购买价格'})
        fieldList.push({type:'string',value:'useDesc',text:'使用规则说明'})
        fieldList.push({type:'int',value:'useStatus',text:'使用状态 0 未使用 1 已核销 2 已过期'})
        fieldList.push({type:'date',value:'receiveDate',text:'领取时间'})
        fieldList.push({type:'date',value:'checkDate',text:'核销时间'})
        fieldList.push({type:'string',value:'checkUser',text:'核销手机号'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>